package com.fdb.efp.console.api.rest;

import com.fdb.basic.framework.core.constant.DataRuleType;
import com.fdb.basic.framework.core.constant.ResponseData;
import com.fdb.basic.framework.web.controller.AbstractController;
import com.fdb.efp.console.service.facade.SRoleDataRuleService;
import com.fdb.efp.console.service.facade.BizPluginServiceService;
import com.fdb.efp.console.service.vo.BizPluginServiceVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class BizPluginServiceController extends AbstractController  {

	@Autowired
	@Qualifier("bizPluginServiceService")
	private BizPluginServiceService bizPluginServiceService;
	@Autowired
	@Qualifier("sRoleDataRuleService")
	private SRoleDataRuleService sRoleDataRuleService;


	/**
	 * 列表数据查询
	 * @param page
	 * @param size
	 * @return
	 */
	@RequestMapping(value="/biz/plugin/services", method=RequestMethod.POST)
	public @ResponseBody ResponseData<List<BizPluginServiceVO>> queryBizPluginServiceAll(
			@RequestBody BizPluginServiceVO vo) {
//		List<BizPluginServiceVO> outputVo = this.executeQueryList("queryAll", bizPluginServiceService, new Object[]{vo});
//		return getResponseData(outputVo);
		//setUserInfoToVO(vo);
		// 根据用户角色获取用户权限方案
		//Map<String,String> dataRuleTypeMap = sRoleDataRuleService.getDataRuleType(httpRequest.getRequestURI(), getUserRoles());
		List<BizPluginServiceVO> outputVo = null;
		//DataRuleType dataRuleType = DataRuleType.getDataRuleType(dataRuleTypeMap == null ? null:dataRuleTypeMap.get(PubConstant.PERMIS_TYPE));
		DataRuleType dataRuleType =DataRuleType.getDataRuleType("01");
		// 根据权限方案调用不同的方案进行数据查询
		switch (dataRuleType) {
			case Owner:
				outputVo = bizPluginServiceService.queryAllOwner(vo);
				break;
			case CurrOrg:
				outputVo = bizPluginServiceService.queryAllCurrOrg(vo);
				break;
			case CurrDownOrg:
				outputVo = bizPluginServiceService.queryAllCurrDownOrg(vo);
				break;
			default:
				outputVo = bizPluginServiceService.queryAllOwner(vo);
				break;
		}
		return getResponseData(outputVo);

	}

	/**
	 * 根据主键查询详情
	 * @return
	 */
	@RequestMapping(value="/biz/plugin/service/{bizPluginId}", method=RequestMethod.GET)
	public @ResponseBody ResponseData<BizPluginServiceVO> queryByPk(@PathVariable("bizPluginId") String bizPluginId) {
		BizPluginServiceVO inVo = new BizPluginServiceVO();
		inVo.setBizPluginId(bizPluginId);
		BizPluginServiceVO outputVo = bizPluginServiceService.queryByPk(inVo);
		return getResponseData(outputVo);

	}

	/**
	 * 根据主键删除信息
	 * @param bizPluginService
	 * @return
	 */
	@RequestMapping(value="/biz/plugin/service", method=RequestMethod.DELETE)
	public @ResponseBody ResponseData<Integer> deleteByPk(@RequestBody BizPluginServiceVO inBizPluginServiceVo) {
		int outputVo = bizPluginServiceService.deleteByPk(inBizPluginServiceVo);
		return getResponseData(outputVo);

	}

	/**
	 * 根据主键更新信息
	 * @param inBizPluginServiceVo
	 * @return
	 */
	@RequestMapping(value="/biz/plugin/service", method=RequestMethod.PUT)
	public @ResponseBody ResponseData<Integer> updateByPk(@RequestBody BizPluginServiceVO inBizPluginServiceVo) {
		int outputVo = bizPluginServiceService.updateByPk(inBizPluginServiceVo);
		return getResponseData(outputVo);

	}

	/**
	 * 新增数据
	 * @param inBizPluginServiceVo
	 * @return
	 */
	@RequestMapping(value="/biz/plugin/service", method=RequestMethod.POST)
	public @ResponseBody ResponseData<Integer> insertBizPluginService(@RequestBody BizPluginServiceVO inBizPluginServiceVo) {
		int outputVo = bizPluginServiceService.insertBizPluginService(inBizPluginServiceVo);
		return getResponseData(outputVo);

	}
	/**
	 * 新增数据,并且返回这个对象
	 * @param inBizPluginServiceVo
	 * @return
	 */
	@RequestMapping(value="/biz/plugin/service/back", method=RequestMethod.POST)
	public @ResponseBody ResponseData<BizPluginServiceVO> insertBizPluginServiceBack(@RequestBody BizPluginServiceVO inBizPluginServiceVo) {
		inBizPluginServiceVo = bizPluginServiceService.insertBizPluginServiceBack(inBizPluginServiceVo);
		return getResponseData(inBizPluginServiceVo);

	}
}
